/*
 * ElementData.cpp
 *
 *  Created on: May 29, 2011
 *      Author: madboyka
 */

#include "ElementData.h"
#include <string.h>
#include <stdio.h>
#include <string.h>

ElementData::ElementData(ElementType type)
{
	elementType = type;
	data = 0;
	dataCount = 0;
	transformationMatrix = 0;
}

ElementData::ElementData(const ElementData& other)
{
	//    printf("ELEMENTM AMAOLSO HETCESCSEG %d|\n", other.dataCount);
	data = 0;
	transformationMatrix = 0;
	elementType = other.elementType;
	//        for (int i = 0; i < other.dataCount; ++i)
	//        {
	//            printf("%f, ", other.data[i]);
	//        }
	setColor(other.color[0], other.color[1], other.color[2]);
	if (elementType == MeshType)
	{
		setMeshType(other.getMeshType());
	}
	else
	{
		setData(other.dataCount, (float*) other.data);
	}
	setTransformationMatrix(other.transformationMatrix);

	//        for (int i = 0; i < dataCount; ++i)
	//        {
	//            printf("asdf%f, ",data[i]);
	//        }
}

ElementData::~ElementData()
{
	if (elementType == MeshType)
	{
		delete[] (char*) data;
	}
	else
	{
		delete[] (float*) data;
	}
	delete[] transformationMatrix;
}

void ElementData::setTransformationMatrix(float *mat)
{
	transformationMatrix = new float[16];
	//	puts("MECPY1");
	memcpy((void*) transformationMatrix, (void*) mat, sizeof(float) * 16);
	//	puts("MECPY2");
}

void ElementData::setData(int count, float *datas)
{
	dataCount = count;
	if (dataCount > 0)
	{
		data = new float[dataCount];
		//		puts("MECPY1X");
		memcpy((void *) data, (void*) datas, sizeof(float) * dataCount);
		//		puts("MECPY2X");
	}
}

void ElementData::setColor(unsigned char r, unsigned char g, unsigned char b)
{
	color[0] = r;
	color[1] = g;
	color[2] = b;
}

unsigned char * ElementData::getColor() const
{
	return (unsigned char *) color;
}

float* ElementData::getTransformationMatrix() const
{
	return transformationMatrix;
}

float* ElementData::getData() const
{
	return (float*) data;
}

char* ElementData::getMeshType() const
{
	return (char*) data;
}

void ElementData::setMeshType(const char *type)
{
	data = new char[strlen(type) + 1];
	strcpy((char*) data, type);
}

int ElementData::getDataCount() const
{
	return dataCount;
}

ElementType ElementData::getElementType() const
{
	return elementType;
}
